package thread;

public class threadDemo12 {
    public static int num=0;
    //线程安全问题
    public static void main(String[] args) throws InterruptedException {
        Object ram=new Object();
        Thread t1=new Thread(()->{
            for (int i = 0; i <50000 ; i++) {
                //加锁
                //synchronized (ram){
                    num++;
                //}

            }
        });
        Thread t2=new Thread(()->{
            for (int i = 0; i <50000 ; i++) {
                //synchronized (ram) {
                    num++;
                //}
            }
        });
        t1.start();
        t2.start();

        t1.join();
        t2.join();
        System.out.println("num="+num);
    }
}
